package com.zy.edu.controller;


import com.zy.edu.bean.InputParam;
import com.zy.edu.bean.ToolInfo;
import com.zy.edu.service.ToolInfoService;
import com.zy.edu.service.ToolInfoService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HuangHaiShui
 * @since 2021-08-24
 */
@RestController
@RequestMapping("/tool")
public class ToolInfoController {

    @Resource
    ToolInfoService toolInfoService;

    /**
     * @Author: HuangHaiShui
     * @Description: 数据的新增与修改
     * @Date: 9:17 2021/8/24
     * @param toolInfo:
     * @return: Map
     **/
    @RequestMapping("/edit")
    public Map edit(@Valid ToolInfo toolInfo){
        return toolInfoService.saveOrUpdate(toolInfo);
    }

    /**
     * @Author: HuangHaiShui
     * @Description:数据数据的查询，可分页可查全部
     * @Date: 9:17 2021/8/24
     * @param toolInfo:    name 模糊查询
     * @param inputParam:  分页条件
     * @return: Map
     **/
    @RequestMapping("/list")
    public Map list( ToolInfo toolInfo, InputParam inputParam){

        return toolInfoService.list(toolInfo, inputParam);
    }

    @RequestMapping("/getById")
    public Map getById(ToolInfo toolInfo, InputParam inputParam){

        return toolInfoService.getById(toolInfo, inputParam);
    }
    /**
     * @Author: HuangHaiShui
     * @Description: 删除数据
     * @Date: 9:18 2021/8/24
     * @param toolInfo:  传入id 字段
     * @return: Map
     **/
    @RequestMapping("/dele")
    public Map dele( ToolInfo toolInfo){
        return toolInfoService.dele(toolInfo);
    }

    //封面的上传
    @RequestMapping("photo")
    public Map photo(MultipartFile file, @Valid InputParam inputParam  ) throws IOException {

        return toolInfoService.photo(file,inputParam);
    }

}

